package com.support.android.myapp3.customComponent.dialog;

import android.text.TextUtils;
import android.view.View;

import com.support.android.myapp3.R;


/**
 * 确定样式Dialog
 */
public class ConfirmDialog extends BaseDialog {

    private String title;
    private String message;
    private ClickListener cancelClickListener;
    private ClickListener confirmClickListener;

    public static ConfirmDialog newInstance() {

        ConfirmDialog dialog = new ConfirmDialog();
        return dialog;
    }

    @Override
    public int setUpLayoutId() {
        return R.layout.dialog_confirm;
    }

    @Override
    public void convertView(ViewHolder holder, final BaseDialog dialog) {
        if (!TextUtils.isEmpty(title)) {
            holder.setText(R.id.title, title);
        }

        if (!TextUtils.isEmpty(message)) {
            holder.setText(R.id.message, message);
        }

        if (cancelClickListener != null) {
            holder.setOnClickListener(R.id.cancel, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
//                dialog.dismiss();
                    cancelClickListener.onClick(dialog);
                }
            });
        }

        if (confirmClickListener != null) {
            holder.setOnClickListener(R.id.confirm, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
//                    dialog.dismiss();
//                    Toast.makeText(getContext(), "确定", Toast.LENGTH_SHORT).show();
                    confirmClickListener.onClick(dialog);
                }
            });
        }
    }

    public ConfirmDialog setTitle(String title) {
        this.title = title;
        return this;
    }

    public ConfirmDialog setMessage(String message) {
        this.message = message;
        return this;
    }

    public ConfirmDialog setCancelClickListener(ClickListener listener){
        this.cancelClickListener = listener;
        return this;
    }

    public ConfirmDialog setConfirmClickListener(ClickListener listener){
        this.confirmClickListener = listener;
        return this;
    }

    public interface ClickListener {
        void onClick(final BaseDialog dialog);
    }


}
